package com.wiloon.java8x.sort;

/**
 * Created with IntelliJ IDEA.
 * User: wiloon
 * Date: 9/16/12
 * Time: 3:44 PM
 */

//具体的比较类，实现Comparator接口

import java.util.Comparator;


public class ComparatorUser implements Comparator {


    public int compare(Object arg0, Object arg1) {

        User user0 = (User) arg0;

        User user1 = (User) arg1;


        //首先比较年龄，如果年龄相同，则比较名字


        int flag = user0.getAge().compareTo(user1.getAge());

        if (flag == 0) {

            return user0.getName().compareTo(user1.getName());

        } else {

            return flag;

        }

    }


}
